<?php
namespace app\common\model;

use Exception;

class Code extends Base
{
    // protected $name = 'admin';

    /**
     * 验证码验证
     * @param string $mobile 手机号
     * @param int    $code  验证码
     * @return array
     */
    public static function checkCode($mobile, $code)
    {
        $res = self::getFind(['mobile' => $mobile, 'is_use' => 0], '*', 'id desc');

        if ($res == false) return '手机号错误';
        if ($code != $res['code']) return '验证码错误';
        if (time() > $res['expiration_time']) return '验证码已过期';

        return true;
    }
}